package com.yz.xyt.service.impl;

import com.yz.xyt.service.IFileService;
import com.yz.xyt.utils.FileUploadUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件处理service
 * @author JW.WANG
 */
@Service
public class FileServiceImpl implements IFileService {

    @Value("${xyt.profile}")
    private String baseDir;


    /**
     * 文件上传
     * @param uploadDir
     * @param file
     * @return
     * @throws IOException
     */
    @Override
    public String uploadFile(String uploadDir, MultipartFile file) throws IOException {

        if(StringUtils.isEmpty(uploadDir)){
            uploadDir = baseDir;
        }
        return FileUploadUtils.upload(file,uploadDir);
    }
}
